#include<16f877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=11592000)

#define HIGH 1
#define LOW 0
#define MOT1 PIN_C1
#define MOT2 PIN_C2
#define MOT3 PIN_C3
#define MOT4 PIN_C4

void forward()
 {
output_bit(MOT1,HIGH);
output_bit(MOT2,LOW);
output_bit(MOT3,LOW);
output_bit(MOT4,HIGH);
 }
void reverse()
 {
output_bit(MOT1,LOW);
output_bit(MOT2,HIGH);
output_bit(MOT3,HIGH);
output_bit(MOT4,LOW);
 }
void turn_left()
 {
output_bit(MOT1,LOW);
output_bit(MOT2,HIGH);
output_bit(MOT3,LOW);
output_bit(MOT4,LOW);
 }
void turn_right()
{
output_bit(MOT1,LOW);
output_bit(MOT2,LOW);
output_bit(MOT3,HIGH);
output_bit(MOT4,LOW);
}
void stop()
 {
output_bit(MOT1,LOW);
output_bit(MOT2,LOW);
output_bit(MOT3,LOW);
output_bit(MOT4,LOW);
 }

void main()
{
   unsigned char sw;
   port_b_pullups(true);
   output_c(0x00);
   output_b(0x00);
  
   while(1)
   {
   sw=input_B();
   
   if((sw&0x0f)==0b0001110)
 {
   forward();

  // output_C(0xAA);//front
    delay_ms(100);
  // output_c(0x00);
 //  forward();
    
   }
   if((sw&0x0f)==0b0001101)
  {   
    reverse();
   //output_C(0x55);//back
    delay_ms(100);
  // output_c(0x00);     
   }
   if((sw&0x0f)==0b0001011)
  {
   turn_left();
  // output_C(0x99);//right
    delay_ms(100);
 //  output_c(0x00);
   
   }
   if((sw&0x0f)==0b0000111)
   {
   turn_right();
 //  reverse();
  // output_C(0x66);//left
   delay_ms(100);
 //  output_c(0x00);
  
   }
   
   }
}
